package com.adrninistrator.javacg.writer;

import com.adrninistrator.javacg.common.enums.JavaCGWriterKeyEnum;
import com.adrninistrator.javacg.conf.JavaCGConfInfo;
import com.adrninistrator.javacg.util.JavaCGFileUtil;

import java.io.FileNotFoundException;
import java.io.Writer;

/**
 * 根据配置的写入方式生成对应的Writer
 */
public final class WriterFactory {
    public static Writer getWriter(JavaCGConfInfo confInfo, JavaCGWriterKeyEnum javaCGWriterKeyEnum, String path) throws RuntimeException, FileNotFoundException {
        Writer writer = null;
        if (javaCGWriterKeyEnum == JavaCGWriterKeyEnum.WTE_METHOD_CALL) {
            writer = confInfo.getWriterMap().get(javaCGWriterKeyEnum.getWriteKey());
            if (writer == null) {
                writer = JavaCGFileUtil.genBufferedWriter(path);
            }
        }
        return writer;
    }
}
